import requests
# 请求JSON格式数据，查看返回状态码
header={'User-Agent':'imooc'}
response=requests.get(url='http://httpbin.org/ip',headers=header)
print(response.json());print(response.json()['origin'])
print(response.status_code)
print(response.request.headers)
# 用post方法向目标网址发送数据
response=requests.post('http://httpbin.org/post',data={'name':'imooc'})
print(response.text)
# 用get方法向目标网址发送数据
data={'key1':'value1','key2':'value2'}
response=requests.get('http://httpbin.org/get',params=data)
print(response.url)
print(response.headers)
# 请求图片格式数据并保存到本地
url='https://www.imooc.com/static/img/index/logo2020.png'
response=requests.get(url)
print(response.content)
with open('imooc.png','wb') as f:
    f.write(response.content)
